const express = require('express');
const path = require('path');
const fs = require('fs');
const app = express();

// 设置静态文件目录
app.use(express.static(path.join(__dirname, 'public')));

// 引入各应用路由
const galleryRouter = require('./routes/gallery');

// 主应用路由
app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, 'public/index.html'));
});

// 微应用路由
app.get('/apps/:appName', (req, res) => {
    const appName = req.params.appName;
    res.sendFile(path.join(__dirname, `public/apps/${appName}/index.html`));
});

// 注册各应用API路由
app.use('/api/gallery', galleryRouter);

const PORT = process.env.PORT || 80;
app.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
});